﻿#region Using Directives

using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections.Generic;

using QuickDev.Common.Audit;
using QuickDev.Common.Utils;

using QuickDev.Localization;
using QuickDev.Web.UI;

using QuickDev.Model;
using QuickDev.Caching;

#endregion

namespace QuickDev.Web.App.Administration
{
    public partial class SiteSettingConfiguration : AdminPage
    {
        #region Member Variables

        private string view = string.Empty;
        private SiteSettings siteSettings = null;

        #endregion

        #region Page Events

        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load( object sender, EventArgs e )
        {
            try
            {
                view = Utility.GetParameter( "view" );
                LoadSiteSettings();

                switch ( view )
                {
                    case "g":
                        generalSiteSettings.Visible = true;
                        generalSiteSettings.SiteSettings = siteSettings;
                        break;

                    case "c":
                        cachingSettings.Visible = true;
                        cachingSettings.SiteSettings = siteSettings;
                        break;

                    case "a":
                        analytics.Visible = true;
                        analytics.SiteSettings = siteSettings;
                        break;

                    case "i":
                        imagesSettings.Visible = true;
                        imagesSettings.SiteSettings = siteSettings;
                        break;

                    case "bc":
                        broadcast.Visible = true;
                        broadcast.SiteSettings = siteSettings;
                        break;

                    case "gl":
                    default:
                        globalizationSettings.Visible = true;
                        globalizationSettings.SiteSettings = siteSettings;
                        break;
                }
            }
            catch ( Exception ex )
            {
                Logger.Error( typeof( SiteSettingConfiguration ).Name + ".Page_Load", ex );
                Master.MessageCenter.DisplayCriticalMessage( ex.Message );
            }
        }

        #endregion

        #region Methods

        #region Private

        /// <summary>
        /// Loads the site settings.
        /// </summary>
        private void LoadSiteSettings()
        {
            siteSettings = SiteSettingsCache.GetCachedModel();
            if ( siteSettings == null )
            {
                siteSettings = new SiteSettings();
            }
        }

        #endregion

        #endregion
    }
}
